import theano.tensor as T

def zero_one_loss(truth, predictions):
    return T.sum(T.neq(T.argmax(predictions), truth))


# NLL is a symbolic variable ; to get the actual value of NLL, this symbolic
# expression has to be compiled into a Theano function (see the Theano
# tutorial for more details)
def negative_log_likelihood(truth, predictions):
    vector = T.arange(truth.shape[0])
    vectorMatrix = T.log(predictions)[vector, truth]
    return -T.sum(vectorMatrix)
# note on syntax: T.arange(y.shape[0]) is a vector of integers [0,1,2,...,len(y)].
# Indexing a matrix M by the two vectors [0,1,...,K], [a,b,...,k] returns the
# elements M[0,a], M[1,b], ..., M[K,k] as a vector.  Here, we use this
# syntax to retrieve the log-probability of the correct labels, y.